var listObj = (function ($) {
	var sourceData;
	var pageType = '', method=''
	var start = 0,Limit = 20;
	var pullDom;
	var pulling = false;
	var nurseId='',perInfo='',perId=''
	$.init();
	$.plusReady(function() {
		baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	function getListData(){
		if (pulling) {
			pullDom.endPullUpToRefresh()
			return;
		}
		pulling = true
		var pdict = {'start':start,'limit':Limit,'parr':perId}
		var stDate = $('#stBtn')[0].innerText
		var endDate = $('#endBtn')[0].innerText
		
		if (pageType == '调配申请') {
			var parr = 'StDate|'+stDate+'^EndDate|'+endDate+'^Person|'+perInfo['loginName']+'^Ward|'+perInfo['loginWardId']+'^Status|'
			pdict = {'start':start,'limit':Limit,'parr':parr,'id':nurseId,'roles':perInfo['loginRoleCodes']}
		}else if (pageType == '离职备案') {
			//冯亮^1^^2022-08-31^ //护士姓名^病区^开始日期^结束日期
			var parr = perInfo['loginCode']+'^'+perInfo['loginWardId']+'^'+stDate+'^'+endDate+'^'
			pdict = {'start':start,'limit':Limit,'parr':parr,'nurseid':nurseId,'roles':perInfo['loginRoleCodes'],'nursetype':'N'}
		}else if (pageType == '专科发展备案') {
			var parr = '^^^^^^'+perId
			pdict = {'start':start,'limit':Limit,'parr':parr,'nurseid':nurseId}
		}
		var paramDict = {'method':method,'params':JSON.stringify(pdict),'type':'RecQuery'}
		//console.log(JSON.stringify(pdict)+ ' ' +method)
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result.msgcode != '1') {
				pullDom.endPullUpToRefresh();
				pulling = false
				mui.toast(result.msg)
				return;
			}
			var dataArr = result.data
			if (start == 0) {
				sourceData = dataArr;
			}else{
				sourceData = sourceData.concat(dataArr)
			}
			updateUI(dataArr)
			if (dataArr.length < Limit) {
				pullDom.endPullUpToRefresh(true);
			}else{
				pullDom.endPullUpToRefresh();
			}
			start += dataArr.length;
			pulling = false
		}, function(errorStr) {
		 	pullDom.endPullUpToRefresh();
		 	pulling = false
		});
	}
	function updateUI(dataArr){
		var UL = $('#UL')[0];
		if (start == 0) {
			mui('#UL li').each(function (index,element) {
				element.removeEventListener('tap',tableCellTapped)
			})
			UL.innerHTML = ''
		}
		var oldCount = UL.querySelectorAll('li').length;
		for(var i=0; i<dataArr.length; i++){
			var oneData = dataArr[i]
			var html = getListHtml(pageType,oneData,perInfo)
			var newLi = document.createElement('li')
			newLi.setAttribute('class','mui-table-view-cell')
			newLi.innerHTML = html
			newLi.id = 'li-'+(oldCount+i);
			UL.appendChild(newLi)
			newLi.addEventListener('tap',tableCellTapped)
		}
	}
	function tableCellTapped(){
		var indexStr = this.id.split('-')[1]
		var index = parseInt(indexStr)
		var currData = sourceData[index]
		if (this.querySelector('.nur-statusS')) {
			var pageName = getApplyNewPageName(pageType)
			var webview = plus.webview.create(pageName+'.html', pageName, {
				background: '#fff',
				statusbar: {
					background: '#fff'
				}
			},{'pageType':pageType,'data':currData,'perInfo':perInfo});
			webview.show('fade-in');
			return
		}
		var webview = plus.webview.create('applyDetail.html', 'applyDetail', {
			background: '#fff',
			statusbar: {
				background: '#fff'
			}
		},{'data':currData,'pageType':pageType});
		webview.show('fade-in');
	}

	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		var self = plus.webview.currentWebview()
		pageType = self.title
		perInfo = app.getState()
		nurseId=perInfo['loginID']
		perId=perInfo['loginPerID']
		if (pageType == '调配申请' || pageType == '离职备案') {
			document.body.classList.add('hasDate')
			var stBtn = $('#stBtn')[0]
			var endBtn = $('#endBtn')[0]
			var curMonth = getDeviceYearMonthStr();
			stBtn.innerText = curMonth +'-01'
			var currDict = getYMDWithStr(curMonth)
			endBtn.innerText = curMonth +'-' + getMonthMaxDay(currDict['year'], currDict['month'])
			stBtn.addEventListener('tap',dateBtnTapped)
			endBtn.addEventListener('tap',dateBtnTapped)
		}
		$('.mui-title')[0].innerText = pageType
		method = getListMethod(pageType)
		var scroll = document.getElementById('scroll');
		pullDom = $(scroll).pullToRefresh({
			up: {
				callback: function() {
					getListData()
				}
			}
		});
		getListData();
		//新建按钮
		mui('body').on('tap','#addBtn',function(){
			var pageName = getApplyNewPageName(pageType)
			var webview = plus.webview.create(pageName+'.html', pageName, {
				background: '#fff',
				statusbar: {
					background: '#fff'
				}
			},{'pageType':pageType,'perInfo':perInfo});
			webview.show('fade-in');
		})
		if ('调配申请,投诉备案,表扬备案'.indexOf(pageType) != -1) {
			if (pageType != '调配申请') {
				return //投诉备案,表扬备案隐藏此功能
			}
			document.body.classList.add('hasStat') //显示统计按钮
			//统计按钮
			mui('body').on('tap','#statBtn',function(){
				var webview = plus.webview.create('../platformStat.html', 'platformStat', {
					background: '#fff',
					statusbar: {
						background: '#fff'
					}
				},{'pageType':pageType,'nurseid':nurseId,'perId':perId,'title':pageType});
				webview.show('fade-in');
			})
		}
	}
	function dateBtnTapped(){
		var _self = this;
		plus.nativeUI.pickDate(function(e) {
			var d = e.date;
			var dateStr = d.getFullYear()+'-'
			if (d.getMonth() < 9) {
				dateStr += '0'
			}
			dateStr += (d.getMonth() + 1)+'-'
			if (d.getDate() < 10) {
				dateStr += '0'
			}
			dateStr += d.getDate()
			_self.innerText = dateStr;
			resetListRefresh();
		}, function(e) {}, {});
	}
	var resetListRefresh = function (){
		start = 0;
		sourceData = []
		mui('#UL li').each(function (index,element) {
			element.removeEventListener('tap',tableCellTapped)
		})
		 $('#UL')[0].innerHTML = '';
		 $('#wrapper').scroll().scrollTo(0,0,100);
		if (pullDom) {
			pullDom.refresh(true)
		}
		getListData();
	}
	var exportObj = {}
	exportObj.resetListRefresh = resetListRefresh
	return exportObj
})(mui)

function detailChanged(){
	listObj.resetListRefresh();
}

/*
调配申请  
	列表 web.INMPersonComm:FindTransApp  parr='StDate|^EndDate|2022-08-31^Person|^Ward|^Status|'
	{"AppWard":"产房","TransStatus":"审核通过","AppDate":"2020-10-29","AppNur":"汪雨铃","RowID":"2","AppWardId":"2","CreateUserPr":"26",
	"AppDays":"29","AppCount":"1","PlanStDate":"2020-11-01","PlanEndDate":"2020-11-30","PlanDays":"29"}
	详情  web.INMPersonComm:GetTransRec  RecMethod
	{"AppDate":"2020-10-29","AppNur":"汪雨铃","AppNurCondition":"","AppNurCount":"1","AppReason":"疫情原因，患者书增多","AppRemark":"",
	"AppSalary":"","AppStatus":"审核通过","AppWard":"产房","NoCheck":"A","NoCheckReason":"通过","PlanDays":"29","PlanEndDate":"2020-11-30",
	"PlanStDate":"2020-11-01","RowID":"2"}
投诉备案
	列表  web.INMPerSubComm:FindCriticList  parr=nurseid
	{"criticStatus":"保存","criticDeal":"待处理","criticRectifEffect":"良好","criticDate":"2022-08-09","criticFrom":"批评","criticRowID":"1"}
	详情  web.INMPerSubComm:GetCriticIte  parr={'id':id}
	{"RowID":"1","criticBack":"亮亮","criticDate":"2022-08-09","criticDeal":"待处理","criticDesc":"事件描述","criticFrom":"64||1",
	"criticRecordDate1":"2022-08-09","criticRecordDate2":"1840-12-31","criticRecorder1":"冯亮","criticRecorder2":"",
	"criticRectifAction":"整改措施","criticRectifEffect":"良好","criticStatus":"保存"}
职称备案
	列表  web.INMPersonComm:FindDutyList  parr=nurseid
	{"hireDuty":"主管护师","hireStDate":"2021-11-25","hireEndDate":"","hireRemark":"","hireRowID":"24","status":"审核",
	"MajorDuty":"主管护师","MajorDutyDate":"2021-11-12"}
	详情  web.INMPersonComm:GetDutyItem  parr={'id':id}
	{"HireDuty":"12||3","HireEndDate":"2022-08-31","HireRemark":"备注","HireStDate":"2022-08-01","MajorDuty":"12||3",
	"MajorDutyDate":"2022-07-31","RowID":"35"}
职务备案
	列表  web.INMPersonComm:FindPostList  parr=nurseid
	{"postDuty":"护士长","postStDate":"2020-07-01","postEndDate":"","postRemark":"","postRowID":"53","status":"审核"}
	详情  web.INMPersonComm:GetPostItem  parr={'id':id}
	{"PostDuty":"14||22","PostEndDate":"2022-09-01","PostRemark":"备注","PostStDate":"2022-08-01","RowID":"68"}
	
资格注册备案
	列表  web.INMPerSubComm:FindRegistedList  parr=nurseid
	{"RegistedStatus":"审核","RegistedDate":"2020-09-14","RowID":"2"}
	详情  web.INMPerSubComm:GetRegistedItem  parr={'id':id}
	{"RegistedDate":"2022-08-01","RowID":"23"}
	
离职备案
	列表  web.INMInternComm:FindResignLists  parr=nurseid
	{"resignStatu":"A","resignStatuDesc":"已审核","resignNo":"","nurseID":"","resignName":"孙乐韬","resignWard":"CCU","resignDate":"2021-07-07",
	"resignReason":"","creater":"管理员","createDate":"2021-03-04","updateUser":"管理员","resignUpdate":"2021-07-06","rowid":"7"}
	详情  web.INMInternComm:GetResign  parr={'id':id}
	{"ResignDate":"","ResignName":"1393","ResignOpinion":"","ResignOther":"","ResignReason":"20||1~20||3~20||5","ResignStatus":"N","ResignWard":"1","RowID":"13"}
	
教育信息备案
	列表  web.INMPersonComm:FindEduList  parr=nurseid
	{"eduStDate":"2020-09-09","eduEndDate":"2022-06-30","eduSchool":"河南中医学院","eduAcademic":"博研","eduDegree":"博士","eduRowID":"20",
	"eduProfession":"护理","eduRadio":"全日制","eduDegreeDate":"2022-08-01","eduAcadeType":"最高学历","status":"保存"}
	详情  web.INMPersonComm:GetEduItem  parr=
	{"EduAcademic":"3||4","EduDegree":"15||3","EduDegreeDate":"2022-08-01","EduEndDate":"2022-06-30","EduProfession":"22||7",
	"EduRadio":"23||1","EduSchool":"18||117","EduStDate":"2020-09-09","RowID":"20"}
	
工作经历备案
	列表  web.INMPersonComm:FindWorkList  parr=nurseid
	{"workStDate":"2021-08-01","workEndDate":"2022-08-01","workUnit":"工作单位","workPost":"处长","workDuty":"护士","workRemark":"备注",
	"workRowID":"1","worktype":"","workStatus":"保存","statusCode":"N"}
	详情  web.INMPersonComm:GetWorkItem  parr=
	{"RowID":"1","WorkDuty":"12||1","WorkEndDate":"2022-08-01","WorkPost":"14||22","WorkRemark":"备注","WorkStDate":"2021-08-01","WorkUnit":"工作单位"}
	
进修备案
	列表  web.INMPerSubComm:FindStudyList  parr=nurseid
	{"studyStatus":"驳回","studyStDate":"2022-01-06","studyEndDate":"2022-01-13","studyProfession":"123","studyHospital":"32","studyLength":"8","studyRowID":"3"}
	详情  web.INMPerSubComm:GetStudyItem  parr=
	{"RowID":"3","studyEndDate":"2022-01-13","studyHospital":"32","studyLength":"8","studyProfession":"123","studyStDate":"2022-01-06","studyStatus":"驳回"}
专科发展备案
	列表  web.INMSpecialComm:FindSpecialList  parr=^^^^^^338
	{"SpecialPer":"1","SpecialPerName":"冯亮","SpecialType":"66__1","SpecialTypeDesc":"手术专科证书","SpecialAuth":"67__1",
	"SpecialAuthDesc":"协和医院","SpecialAuthDate":"2020-12-01","SpecialCertificate":"","SpecialStatus":"A",
	"SpecialStatusDesc":"审核","Creator":"0","CreatorName":"管理员","CreateDate":"2020-12-04","CreateTime":"10:44:59",
	"Auditor":"0","AuditorName":"管理员","AuditDate":"2020-12-04","AuditTime":"19:38:46","AuditOpinion":"1",
	"SpecialNurType":"26__1","SpecialNurTypeDesc":"ICU专科护士","rw":"4","Per":"1","PerName":"冯亮","PerLevel":"N5",
	"PerPost":"带教老师","PerHire":"主管护师","PerCurWard":"CCU","PerStatus":"在职"}
	详情  web.INMSpecialComm:GetSpecial  parr=
	{"AuditDate":"","AuditOpinion":"","AuditTime":"","Auditor":"","AuditorName":"","CreateDate":"2021-11-08",
	"CreateTime":"11:58:06","Creator":"0","CreatorName":"管理员","SpecialAuth":"67__1","SpecialAuthDate":"2021-11-24",
	"SpecialAuthDesc":"协和医院","SpecialCertificate":"","SpecialNurType":"26__1","SpecialNurTypeDesc":"ICU专科护士","SpecialPer":"1",
	"SpecialPerName":"冯亮","SpecialStatus":"Y","SpecialStatusDesc":"提交","SpecialType":"66__1","SpecialTypeDesc":"手术专科证书","rw":"11"}
	
表扬备案
	列表  web.INMPerSubComm:FindPraiseList  parr=nurseid
	{"praiseStatus":"保存","praiseDate":"2022-08-01","praiseFrom":"63||1","praiseFromDesc":"表扬来源1","praiseRowID":"1"}
	详情  web.INMPerSubComm:GetPraiseItem  parr=
	{"RowID":"1","praiseDate":"2022-08-01","praiseDesc":"表扬事件描述","praiseFrom":"63||1","praiseRecordDate":"2022-08-09",
	"praiseRecorder":"冯亮","praiseStatus":"保存"}
社会兼职备案
	列表  web.INMPerSubComm:FindSocialWorkList  parr=nurseid
	{"workStatus":"审核","workType":"院内兼职","workStDate":"2021-05-02","workEndDate":"2022-05-08",
	"workUnit":"神经内科","workPost":"兼职护士","workRemark":"","RowID":"2"}
	详情  web.INMPerSubComm:GetSocialWorkItem  parr=
	{"RowID":"4","workEndDate":"2022-09-01","workLevel":"","workLevelRemark":"级别明细","workPost":"职务","workRemark":"备注",
	"workStDate":"2022-08-01","workStatus":"保存","workType":"65||1","workUnit":"3"}
	
层级备案
	列表  web.INMPersonComm:FindLevelList  parr=nurseid
	{"levelDate":"2022-06-01","nurLevel":"N5","levelRemark":"","levelRowID":"1394","status":"审核","levelFactor":"0"}
	详情  web.INMPersonComm:GetLevelItem  parr=
	{"LevelDate":"2022-08-01","LevelFactor":"5","LevelRemark":"备注","NurLevel":"19||5","RowID":"1395"}
	
*/